/*
 * @Author: 一盏青灯欲锁魂
 * @Date: 2021-06-15 16:35:58
 * @LastEditTime: 2021-06-24 16:58:55
 * @Description: 数据库操作层
 * @FilePath: \nest_demo\src\module\index\index.service.ts
 */
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';

/*
    * jwt生成token步骤：
    *   1. 从'@nestjs/jwt'中引入'JwtService'
    *   
*/

@Injectable()
export class AuthService {
    private readonly user: any[] = [{ username: 'admin', pasword: '1234' }];
    constructor(private readonly jwtService: JwtService) {};

    // 验证用户名密码
    async findUserInfo(username, password): Promise<any> {
        if (username === this.user[0].username) {
            return this.user;
        }
        return false;
    }

    // 登录
    login(username, password) {
        const token = this.jwtService.sign({username, password})
        return token;
    }

    // 鉴权token
    checkAuth() {
        return `权限正确，访问成功！`;
    }
}